<template>
  <p-modal
    :title="title"
    :width="width"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleOk"
    @cancel="handleCancel"
    cancelText="关闭">
    <p-spin :spinning="confirmLoading">
      <p-form :form="form">
        <p-row>
		  <p-col  :span="24">
			<p-form-item label="标签模板编码" :labelCol="labelCol" :wrapperCol="wrapperCol">
        	<p-input readonlyt v-model="EnhanceJS.labelTemplateNo" placeholder="标签模板编码"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="标签模板名称" :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input readonly v-model="EnhanceJS.labelTemplateName" placeholder="标签模板名称"></p-input>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="打印份数 " :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number readonly  v-model="EnhanceJS.labelTemplateLength" :min="1" :trigger-change="true" dictCode="mes_filed_type" style="width: 100%" placeholder="请选择打印份数"/>
			</p-form-item>
		  </p-col>
		  <p-col  :span="24">
			<p-form-item label="本次打印份数 " :labelCol="labelCol" :wrapperCol="wrapperCol">
				<p-input-number   :min="1" :max="EnhanceJS.mesProductLabelId" placeholder="请输入本次打印份数" style="width: 100%"/>
			</p-form-item>
		  </p-col>
	
        </p-row>


      </p-form>
    </p-spin>
  </p-modal>
</template>

<script>


  import { SubmitOnchangMixin } from '@/mixins/SubmitOnchangMixin'
  import { httpAction, putAction, api } from '@/api/manage'
  import pick from 'lodash.pick'
  import fSwitch from '@/components/switch'
  import JDictSelectTag from "@/components/dict/JDictSelectTag"

  export default {
    name: "MesBcFieldModal",
	mixins: [SubmitOnchangMixin],
    components: { 
      JDictSelectTag,
      fSwitch,
    },
    props:{
      EnhanceJS:{
        type:Object,
        required:false,
        default:''
      }
    },
    watch:{
      EnhanceJS(){
        console.log(this.EnhanceJS)
      }
    },
    mounted(){
      console.log(this.EnhanceJS)
    },
    data () {
      return {
        number:1,
        form: this.$form.createForm(this),
        title: '操作',
        width: 800,
        visible: false,
        model: {},
        labelCol: {
          xs: { span: 24 },
          sm: { span: 5 },
        },
        wrapperCol: {
          xs: { span: 24 },
          sm: { span: 16 },
        },

        confirmLoading: false,
        validatorRules:{
        filedCode:{rules: [{ required: true, message: '请输入字段编码!' }]},
        filedName:{rules: [{ required: true, message: '请输入字段名称!' }]},
        filedType:{rules: [{ required: true, message: '请输入字段属性!' }]},
        filedLength:{rules: [{ required: true, message: '请输入字段位数!' }]},
        barcodeBinary:{},
        filedCharacter:{rules: [{ required: true, message: '请输入字段字符!' }]},
        barcodeSource:{rules: [{ required: true, message: '请输入来源!' }]},
        filedSample:{rules: [{ required: true, message: '请输入字段示例!' }]},
        filedExplain:{},
        status:{},
        remark:{},
        },
        url: {
          add: '/mes-code/mesBcField',
          edit: '/mes-code/mesBcField',
        }
     
      }
    },
    created () {
    },
    methods: {
      add () {
        this.edit({});
      },
      edit (record) {
        this.form.resetFields();
        this.model = Object.assign({}, record);
        this.visible = true;
      },
      close () {
        this.$emit('close');
        this.visible = false;
      },
		handleOk () {
      
			const that = this;
			// 触发表单验证
			this.form.validateFields((err, values) => {
			  if (!err) {
				  that.confirmLoading = true;
				  let httpurl = '';
				  let method = '';
          this.formData['mesBcPrintOrderId'] = this.EnhanceJS.id
          this.formData['page']=this.EnhanceJS.mesProductLabelId
				  //新增触发
				  if(!this.model.id){
					httpurl+=this.url.add;
					method = 'post';
					if(this.EnhanceJS.afterAdd){
					  //新增之前
					  let Obj = eval(this.EnhanceJS.afterAdd)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }else{
					//编辑触发
					httpurl+=this.url.edit;
					method = 'put';
					if(this.EnhanceJS.afterEdit){
					 //编辑之前
					  let Obj = eval(this.EnhanceJS.afterEdit)
					  new Obj(this)
					}else{
					  console.log("表单提交数据",formData)
					  that.modalFrom(httpurl,formData,method)
					}
				  }
			  }

      })
     
		},
      handleCancel () {
        this.close()
      },

      
    }
  }
</script>
